<% @rss_feeds = {"#{@project.name} builds" => {:controller => 'projects', :action => 'show', :id => @project, :format => 'rss'}} -%>

<div id="builds_list">
  <div id="navigate_build">
    <% prev_build, next_build = @project.previous_build(@build), @project.next_build(@build)%>
    
    <%= link_to_unless !prev_build, '&lt; prev', 
                       {:project => @project, :build => prev_build}, :accesskey => 'k' %>
    <strong><%= @build.label %></strong>
    <%= link_to_unless !next_build, 'next &gt;', 
                       {:project => @project, :build => next_build}, :accesskey => 'j' %>
    <%= link_to_unless !next_build, 'latest &gt;&gt;', :project => @project.name %>
  </div>
  
  <% @builds_for_navigation_list.each do |build| %>
    <div class="build-link<%= ' selected' if @build.label == build.label %>">
      <%= link_to_build(@project, build) %>
    </div>
  <% end %>

  <div id="builds_drop_down">
    <%= image_tag "spinner.gif" %>
  </div>
  
  <script type="text/javascript">

  <%= remote_function(
        :update => 'builds_drop_down', :method => "GET",
        :url => {:action => 'drop_down', :project => @project},  
        :complete => "selectCurrentBuild()"
        )%>
        
  function selectCurrentBuild() {
    var build = $('build')
    if (!build) return true
    var options = build.options
    for (var i = 0; options.length > i; i++) {
        if(options[i].value == '<%= @build.label %>') {
            build.selectedIndex = i
            build.options[0] = null
        }
    }
  }
  </script>
</div>

<br />

<div id="build_details">
  <h1>
    <%= h @project.name %> build <%= h @build.label %>
    <% if @build.failed? %><span class="error">FAILED</span><% end %>
    <% if @build.incomplete? %> (INCOMPLETE)<% end %>    
  </h1>
  <div class="build_time">
    <%= display_build_time %>
  </div>

  <br/>

  <div class="section_open">
    <div class="section_header" onclick="toggle_section(this.parentNode)">Build Changeset</div>
    <div class="section_content"><%= format_changeset_log(@build.changeset) %></div>
  </div>

  <% test_failures = failures_and_errors_if_any(@build.output) %>
  <% if test_failures %>
    <div class="section_open">
      <div class="section_header" onclick="toggle_section(this.parentNode)">Test Failures and Errors</div>
      <div class="section_content"><%= test_failures %></div>
    </div>
  <% end %>

  <% plugin_errors = @build.plugin_errors %>
  <% unless plugin_errors.empty? %>
    <div class="section_open">
      <div class="section_header" onclick="toggle_section(this.parentNode)">Plugin Errors</div>
      <div class="section_content"><%= h plugin_errors %></div>
    </div>
  <% end %>

  <div class="<%= @build.incomplete? ? 'section_open' : 'section_closed' %>">
    <div class="section_header" onclick="toggle_section(this.parentNode)">Build Log</div>
    <div class="section_content"><div class="logfile"><%= format_build_log(@build.output) %></div><div><%= link_to "See unformatted build log&hellip;", build_artifact_path(:project => @project.name, :build => @build.label, :path => 'build.log') %></div></div>
  </div>

  <% unless @build.additional_artifacts.empty? %>
    <div class="section_open">
      <div class="section_header" onclick="toggle_section(this.parentNode)">Custom Build Artifacts</div>
      <div class="section_content"><% @build.additional_artifacts.each do |artifact| %><div class="artifact"><%= link_to artifact, build_artifact_path(:project => @project.name, :build => @build.label, :path => artifact) %></div><% end %></div>
    </div>
  <% end %>
  
  <div class="section_closed">
    <div class="section_header" onclick="toggle_section(this.parentNode)">Project Settings</div>
    <div class="section_content"><%= format_project_settings(@build.project_settings) %></div>
  </div>


</div>

